// facility/mapScreen/mapScreen.js
import http from '../../http'
import Toast from '@vant/weapp/toast/toast';
let toast;
let num = 0
let timer;
Component({
	options: {
		styleIsolation: 'shared'
	},
	/**
	 * 组件的属性列表
	 */
	properties: {
		infoType: '',
		nowProjectInfo: '',
		nowfacilityInfo: '',
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		bolBindtitle:'甲烷温度设置',
		detailvalue:108,
		actionsshow: true,
		actions: [{
				name: '检测周期设置',
				value: 106
			},
			{
				name: '上报周期设置',
				value: 107
			},
			{
				name: '甲烷温度设置',
				value: 108
			}, {
				name: '水浸值设置',
				value: 110
			},
		],
		// 表单参数
		form: {
			command: undefined, //命令标识
			factoryParams: [],
			order: {} //命令内容
		},
		//设备最新数据
		realData: {},
		programBol: false,
		screenControlBol: false,
		bol: false,
		list: [{
			value: 106,
			text: '检测周期设置'
		}, {
			value: 107,
			text: '上报周期设置'
		}, {
			value: 108,
			text: '甲烷温度设置'
		}, {
			value: 110,
			text: '水浸阈值设置'
		}]
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		bolBind() {
			this.setData({
				bol: true
			})
		},
		// 实时参数
		parameter() {
			if (this.properties.infoType == 'project') {
				wx.showToast({
					title: '请选择传感器',
					icon: 'error',
				})
			} else {
				http.get({
					url: '/zg/iot-links/data/latest/' + this.properties.nowfacilityInfo.id,
					data: {
						// id: this.properties.nowfacilityInfo.id
					},
					then: (res) => {
						console.log('设备最新数据', res);
						let list = {}
						res.data.forEach(item => {
							list = {
								...list,
								...item.formatValue
							}
						})
						// console.log(list.device_location.split(','));
						list.device_lng = list.device_location.split(',')[0]
						list.device_lat = list.device_location.split(',')[1]
						list.sensor_voltage = list.sensor_battery.split(',')[0]
						list.sensor_quantity = list.sensor_battery.split(',')[1]
						this.setData({
							realData: list,
							programBol: true
						})
						console.log(this.data.realData);
					}
				})
			}

		},
		// 参数设置
		screenControl() {
			if (this.properties.infoType == 'project') {
				wx.showToast({
					title: '请选择传感器',
					icon: 'error',
				})
			} else {
				wx.navigateTo({
					url: `../SensorData/SensorData?nowfacilityInfo=${JSON.stringify(this.properties.nowfacilityInfo)}`,
				})
				// this.setData({
				// 	screenControlBol: true,
				// 	actionsshow: true
				// })
			}

		},
		screenControlClose() {
			this.setData({
				screenControlBol: false,
			})
		},
		programClose() {
			this.setData({
				programBol: false,
			})
		},
	}
})